/************************************************************************
 * This module the base API control the serial port.
 * This API can be use on the Windows and Linux platform.
 * When use compile the module,if your platform is Linux,please define the
 * symbol LINUX_GCC_H,and if your platform is Windows,please define the
 * symbol WIN32_VC_H.
 * The author:Zhang YongChang
 * The Date:2012-2-20
 * CopyRight @ robot loving team.
 ************************************************************************/

#ifndef SERIALPORTBASE_H
#define SERIALPORTBASE_H

#include "def.h"

#ifdef WIN32_VC_H
#include <windows.h>
#endif

#ifdef LINUX_GCC_H
#include <stdio.h>     
#include <stdlib.h>   
#include <string.h> 
#include <unistd.h>    
#include <sys/types.h> 
#include <sys/stat.h>  
#include <fcntl.h>     
#include <termios.h>
#include <errno.h>
#endif

namespace robot {

#ifdef LINUX_GCC_H
typedef unsigned char byte;
typedef int hdevice;

enum open_mode {
	write_mode,
	read_mode,
	read_write_mode = O_RDWR
};
#endif

#ifdef WIN32_VC_H
typedef HANDLE hdevice;

enum open_mode {
	write_mode, read_mode, read_write_mode = GENERIC_READ | GENERIC_WRITE
};
#endif

enum serial_error {
	operator_success,
	open_serialport_error,
	close_serialport_error,
	write_serialport_error,
	read_serialport_error
};

serial_error open_serialport(const char * port_name, open_mode mode,
		hdevice &hDev);
serial_error close_serialport(hdevice Dev);
serial_error write_serialport(hdevice hDev, const char * buf, int size);
serial_error read_serialport(hdevice hDev, char * buf, int size);

}

#endif
